package com.studio49.exmple.service.web.sys;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.studio49.exmple.common.constant.ForwardConstant;
import com.studio49.exmple.common.exception.BusinessException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

public interface UserService {

	/**
	 * 后台登录(登录成功会记录日志)
	 * 
	 * @param loginName
	 * @param password
	 * @param request
	 */
	public Short login(String loginName, String password, HttpServletRequest request)
			throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, BusinessException;

    /**
     * 后台用户登录
     *
     * @param loginName
     *            用户名
     * @param password
     *            密码
     * @param request
     * @param response
     * @param map
     * @return
     */
    @RequestMapping(value = "/login")
    default String login(@RequestParam(value = "loginName", required = true) String loginName,
                         @RequestParam(value = "password", required = true) String password, HttpServletRequest request,
                         HttpServletResponse response, Map<String, Object> map) {
        String msg = "";
        try {
            login(loginName, password, request);
            return ForwardConstant.REDIRECT + ForwardConstant.INDEX;
        } catch (BusinessException e) { // 业务异常
            e.printStackTrace();
            msg = e.getMessage();
        } catch (Exception e) { // 系统异常
            e.printStackTrace();
            msg = "登录异常,请联系管理员";
        }
        map.put("msg", msg);
        return ForwardConstant.LOGIN_H;

    }
}
